import React, { PureComponent } from 'react';

import { requireNativeComponent } from 'react-native';

const RCTQiniuStream = requireNativeComponent('RCTQiniuStream', QiniuStream);

export default class QiniuStream extends PureComponent {

    constructor(props) {
        super(props);
        this.onOpenCameraFail = this.onOpenCameraFail.bind(this);
        this.onTorchInfo = this.onTorchInfo.bind(this);
        this.onIoError = this.onIoError.bind(this);
        this.onDisconnected = this.onDisconnected.bind(this);
        this.onShutdown = this.onShutdown.bind(this);
        this.onStreaming = this.onStreaming.bind(this);
        this.onReady = this.onReady.bind(this);
        this.onConnecting = this.onConnecting.bind(this);
    }

    onOpenCameraFail(event) {
        this.props.onOpenCameraFail && this.props.onOpenCameraFail(event.nativeEvent);
    }

    onTorchInfo(event) {
        this.props.onTorchInfo && this.props.onTorchInfo(event.nativeEvent);
    }

    onDisconnected(event) {
        this.props.onDisconnected && this.props.onDisconnected(event.nativeEvent);
    }

    onIoError(event) {
        this.props.onIoError && this.props.onIoError(event.nativeEvent);
    }

    onShutdown(event) {
        this.props.onShutdown && this.props.onShutdown(event.nativeEvent);
    }

    onStreaming(event) {
        this.props.onStreaming && this.props.onStreaming(event.nativeEvent);
    }

    onReady(event) {
        this.props.onReady && this.props.onReady(event.nativeEvent);
    }

    onConnecting(event) {
        this.props.onConnecting && this.props.onConnecting(event.nativeEvent);
    }

    render() {
        return (
            <RCTQiniuStream
                {...this.props}
                onConnecting={this.onConnecting}
                onReady={this.onReady}
                onStreaming={this.onStreaming}
                onShutdown={this.onShutdown}
                onIoError={this.onIoError}
                onDisconnected={this.onDisconnected}
                onTorchInfo={this.onTorchInfo}
                onOpenCameraFail={this.onOpenCameraFail}
            />
        );
    }
}
